package com.zyk.problem;

/**
 * @author zhangsan
 * @date 2021/5/5 12:58
 */
public class SplitSumClosed {

    // 将数组分成两个子序列, 使其两个累加和最接近
    public static int right(int[] nums, int k) {
        int sum = 0;
        for (int num : nums)
            sum += num;
        return process(nums, 0, sum / 2);
    }

    public static int process(int[] nums, int i, int rest) {
        if (i == nums.length) return 0;
        int p1 = process(nums, i + 1, rest);            // 不要这个数
        int p2 = nums[i] <= rest ? process(nums, i + 1, rest) + nums[i] : 0;    //要这个数
        return Math.max(p1, p2);
    }

}
